home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.awt;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.LayoutManager;
- import java.awt.Rectangle;
- import java.awt.Scrollbar;
- import symantec.itools.awt.shape.Rect;
-
- public class ScrollingPanel extends KeyPressManagerPanel {
- private Component spComponent;
- private int width;
- private int height;
- private int xCoord;
- private int yCoord;
- private Scrollbar VBar;
- private Scrollbar HBar;
- private boolean bVBarVisible;
- private boolean bHBarVisible;
- private boolean bCornerRectVisible;
- private boolean bOsFlag;
- private int vPageSize;
- private int hPageSize;
- private Dimension dimComponent;
- private int vGapWid;
- private int hGapHt;
- private boolean bAllowShowVBar;
- private boolean bAllowShowHBar;
- private int scrollLineIncrement;
- private Rect cornerRect;
-
- public ScrollingPanel() {
- this((Component)null, 0, 0);
- }
-
- public ScrollingPanel(Component var1, int var2, int var3) {
- this.bAllowShowVBar = true;
- this.bAllowShowHBar = true;
- this.scrollLineIncrement = 1;
- this.bOsFlag = System.getProperty("os.name").startsWith("S");
- this.spComponent = var1;
- this.width = var2;
- this.height = var3;
- this.xCoord = 0;
- this.yCoord = 0;
- this.bVBarVisible = false;
- this.bHBarVisible = false;
- this.bCornerRectVisible = false;
- this.vPageSize = 0;
- this.hPageSize = 0;
- this.vGapWid = 6;
- this.hGapHt = 6;
- this.dimComponent = new Dimension(0, 0);
- this.VBar = new Scrollbar();
- this.VBar.setBackground(Color.lightGray);
- this.HBar = new Scrollbar(0);
- this.HBar.setBackground(Color.lightGray);
- this.cornerRect = new Rect();
- this.cornerRect.setForeground(Color.lightGray);
- this.cornerRect.setFillColor(Color.lightGray);
- this.cornerRect.setFillMode(true);
- this.setLayout((LayoutManager)null);
- super.add(this.VBar, -1);
- super.add(this.HBar, -1);
- super.add(this.cornerRect, -1);
- this.VBar.hide();
- this.HBar.hide();
- this.cornerRect.hide();
- if (this.spComponent != null) {
- super.add(this.spComponent, -1);
- this.placeComponents();
- }
-
- }
-
- public void setMinimumWidth(int var1) {
- this.width = var1;
- }
-
- public int getMinimumWidth() {
- return this.width;
- }
-
- public void setMinimumHeight(int var1) {
- this.height = var1;
- }
-
- public int getMinimumHeight() {
- return this.height;
- }
-
- public void setVerticalGap(int var1) {
- this.vGapWid = var1;
- ((Component)this).invalidate();
- }
-
- public int getVerticalGap() {
- return this.vGapWid;
- }
-
- public void setHorizontalGap(int var1) {
- this.hGapHt = var1;
- ((Component)this).invalidate();
- }
-
- public int getHorizontalGap() {
- return this.hGapHt;
- }
-
- public void setShowVerticalScroll(boolean var1) {
- if (this.bAllowShowVBar != var1) {
- this.bAllowShowVBar = var1;
- ((Component)this).invalidate();
- }
-
- }
-
- public boolean getShowVerticalScroll() {
- return this.bAllowShowVBar;
- }
-
- public void setShowHorizontalScroll(boolean var1) {
- if (this.bAllowShowHBar != var1) {
- this.bAllowShowHBar = var1;
- ((Component)this).invalidate();
- }
-
- }
-
- public boolean getShowHorizontalScroll() {
- return this.bAllowShowHBar;
- }
-
- public void setScrollLineIncrement(int var1) {
- this.scrollLineIncrement = var1;
- }
-
- public int getScrollLineIncrement() {
- return this.scrollLineIncrement;
- }
-
- public void setComponent(Component var1) {
- if (this.spComponent != null) {
- super.remove(this.spComponent);
- }
-
- this.spComponent = var1;
- super.add(this.spComponent, -1);
- ((Component)this).invalidate();
- }
-
- public Component getComponent() {
- return this.spComponent;
- }
-
- public boolean handleEvent(Event var1) {
- switch (var1.id) {
- case 601:
- if (var1.target == this.HBar) {
- this.scrollLeft();
- } else {
- this.scrollUp();
- }
-
- return true;
- case 602:
- if (var1.target == this.HBar) {
- this.scrollRight();
- } else {
- this.scrollDown();
- }
-
- return true;
- case 603:
- if (var1.target == this.HBar) {
- this.scrollPageLeft();
- } else {
- this.scrollPageUp();
- }
-
- return true;
- case 604:
- if (var1.target == this.HBar) {
- this.scrollPageRight();
- } else {
- this.scrollPageDown();
- }
-
- return true;
- case 605:
- if (var1.target == this.HBar) {
- this.scrollHorizontalAbsolute((Integer)var1.arg);
- } else {
- this.scrollVerticalAbsolute((Integer)var1.arg);
- }
-
- return true;
- default:
- return super.handleEvent(var1);
- }
- }
-
- public void update(Graphics var1) {
- this.paint(var1);
- }
-
- public void paint(Graphics var1) {
- if (this.spComponent != null) {
- this.placeComponents();
- }
- }
-
- public void scrollUp() {
- this.yCoord += this.scrollLineIncrement;
- if (this.yCoord > 0) {
- this.yCoord = 0;
- }
-
- this.VBar.setValue(-this.yCoord);
- ((Component)this).repaint();
- }
-
- public void scrollLeft() {
- this.xCoord += this.scrollLineIncrement;
- if (this.xCoord > 0) {
- this.xCoord = 0;
- }
-
- this.HBar.setValue(-this.xCoord);
- ((Component)this).repaint();
- }
-
- public void scrollDown() {
- this.yCoord -= this.scrollLineIncrement;
- if (-this.yCoord > this.VBar.getMaximum()) {
- this.yCoord = -this.VBar.getMaximum();
- }
-
- this.VBar.setValue(-this.yCoord);
- ((Component)this).repaint();
- }
-
- public void scrollRight() {
- this.xCoord -= this.scrollLineIncrement;
- if (-this.xCoord > this.HBar.getMaximum()) {
- this.xCoord = -this.HBar.getMaximum();
- }
-
- this.HBar.setValue(-this.xCoord);
- ((Component)this).repaint();
- }
-
- public void scrollPageUp() {
- this.yCoord += this.vPageSize;
- if (this.yCoord > 0) {
- this.yCoord = 0;
- }
-
- this.VBar.setValue(-this.yCoord);
- ((Component)this).repaint();
- }
-
- public void scrollPageLeft() {
- this.xCoord += this.hPageSize;
- if (this.xCoord > 0) {
- this.xCoord = 0;
- }
-
- this.HBar.setValue(-this.xCoord);
- ((Component)this).repaint();
- }
-
- public void scrollPageDown() {
- this.yCoord -= this.vPageSize;
- if (-this.yCoord > this.VBar.getMaximum()) {
- this.yCoord = -this.VBar.getMaximum();
- }
-
- this.VBar.setValue(-this.yCoord);
- ((Component)this).repaint();
- }
-
- public void scrollPageRight() {
- this.xCoord -= this.hPageSize;
- if (-this.xCoord > this.HBar.getMaximum()) {
- this.xCoord = -this.HBar.getMaximum();
- }
-
- this.HBar.setValue(-this.xCoord);
- ((Component)this).repaint();
- }
-
- public void scrollVerticalAbsolute(int var1) {
- this.yCoord = -var1;
- if (this.yCoord > 0) {
- this.yCoord = 0;
- } else if (-this.yCoord > this.VBar.getMaximum()) {
- this.yCoord = -this.VBar.getMaximum();
- }
-
- this.VBar.setValue(-this.yCoord);
- ((Component)this).repaint();
- }
-
- public void scrollHorizontalAbsolute(int var1) {
- this.xCoord = -var1;
- if (this.xCoord > 0) {
- this.xCoord = 0;
- } else if (-this.xCoord > this.HBar.getMaximum()) {
- this.xCoord = -this.HBar.getMaximum();
- }
-
- this.HBar.setValue(-this.xCoord);
- ((Component)this).repaint();
- }
-
- public Dimension preferredSize() {
- Dimension var1 = ((Component)this).size();
- Dimension var2 = this.minimumSize();
- return new Dimension(Math.max(var1.width, var2.width), Math.max(var1.height, var2.height));
- }
-
- public Dimension minimumSize() {
- return new Dimension(this.width, this.height);
- }
-
- public Component add(Component var1) {
- if (this.spComponent != null) {
- super.remove(this.spComponent);
- }
-
- this.spComponent = var1;
- super.add(this.spComponent, -1);
- ((Component)this).repaint();
- return var1;
- }
-
- public synchronized Component add(Component var1, int var2) {
- return this.add(var1);
- }
-
- public synchronized Component add(String var1, Component var2) {
- return this.add(var2);
- }
-
- public synchronized void remove(Component var1) {
- if (var1 != this.VBar && var1 != this.HBar) {
- super.remove(var1);
- if (var1 == this.spComponent) {
- this.spComponent = null;
- }
-
- }
- }
-
- public synchronized void removeAll() {
- super.removeAll();
- super.add(this.VBar, -1);
- super.add(this.HBar, -1);
- super.add(this.cornerRect, -1);
- this.spComponent = null;
- }
-
- public void setLayout(LayoutManager var1) {
- }
-
- public synchronized void reshape(int var1, int var2, int var3, int var4) {
- ((Component)this).repaint();
- super.reshape(var1, var2, var3, var4);
- }
-
- void placeComponents() {
- int var3 = 0;
- int var4 = 0;
- int var5 = 0;
- this.dimComponent = this.spComponent.size();
- Rectangle var6 = ((Component)this).bounds();
- var3 = this.bOsFlag ? 17 : 15;
- boolean var2;
- if (this.bAllowShowHBar && this.dimComponent.width > var6.width) {
- var2 = true;
- var5 = var3;
- } else {
- var2 = false;
- var5 = 0;
- }
-
- boolean var1;
- if (this.bAllowShowVBar && this.dimComponent.height > var6.height - var5) {
- var1 = true;
- var4 = var3;
- if (!var2 && this.dimComponent.width > var6.width - var3) {
- var2 = true;
- var5 = var3;
- }
- } else {
- var1 = false;
- var4 = 0;
- }
-
- this.hPageSize = var6.width - var4 - this.vGapWid;
- this.vPageSize = var6.height - var5 - this.hGapHt;
- if (var1) {
- this.VBar.reshape(var6.width - var3, 0, var3, var6.height - var5);
- this.VBar.setValues(-this.yCoord, this.vPageSize, 0, this.dimComponent.height - this.vPageSize);
- this.VBar.setPageIncrement(this.vPageSize);
- if (!this.bVBarVisible) {
- this.bVBarVisible = true;
- this.VBar.show();
- }
- } else {
- if (this.bVBarVisible) {
- this.bVBarVisible = false;
- this.VBar.hide();
- }
-
- this.yCoord = 0;
- }
-
- if (var2) {
- this.HBar.reshape(0, var6.height - var3, var6.width - var4, var3);
- this.HBar.setValues(-this.xCoord, this.hPageSize, 0, this.dimComponent.width - this.hPageSize);
- this.HBar.setPageIncrement(this.hPageSize);
- if (!this.bHBarVisible) {
- this.bHBarVisible = true;
- this.HBar.show();
- }
- } else {
- if (this.bHBarVisible) {
- this.bHBarVisible = false;
- this.HBar.hide();
- }
-
- this.xCoord = 0;
- }
-
- if (this.bHBarVisible && this.bVBarVisible) {
- int var7 = var6.width - var4;
- int var8 = var6.height - var5;
- int var9 = var6.width - var7 + 1;
- int var10 = var6.height - var8 + 1;
- this.cornerRect.reshape(var7, var8, var9, var10);
- if (!this.bCornerRectVisible) {
- this.bCornerRectVisible = true;
- this.cornerRect.show();
- }
- } else if (this.bCornerRectVisible) {
- this.bCornerRectVisible = false;
- this.cornerRect.hide();
- }
-
- this.spComponent.move(this.xCoord, this.yCoord);
- this.spComponent.validate();
- }
- }
-